package com.axiang.module_work.viewmodel;

import android.app.Application;
import androidx.annotation.NonNull;

import com.axiang.lib_api.response.BaseResponse;
import com.axiang.lib_common.mvvm.viewmodel.BaseRefreshViewModel;
import com.axiang.lib_common.network.RefreshObserver;
import com.axiang.module_work.BR;
import com.axiang.module_work.R;
import com.axiang.module_work.bean.HomeMessageBean;
import com.axiang.module_work.model.WorkModel;

import java.util.List;

public class WorkViewModel extends BaseRefreshViewModel<HomeMessageBean.DatasBean, WorkModel> {
    private int pageNo;

    public WorkViewModel(@NonNull Application application, WorkModel model) {
        super(application, model);
    }

    @Override
    public int onBindItemVariableId() {
        return BR.viewModel;
    }

    @Override
    public int onBindItemLayout() {
        return R.layout.item_worklist;
    }

    @Override
    public void refreshData() {
//        postShowNoDataViewEvent(false);
//        if (!NetUtil.checkNetToast()) {
//            postShowNetWorkErrViewEvent(true);
//            return;
//        }
        mModel.getMessageList(pageNo).subscribe(new RefreshObserver<HomeMessageBean, WorkViewModel>(this) {
            @Override
            public void onSuccess(HomeMessageBean homeMessageBeans) {
                List<HomeMessageBean.DatasBean> datasBeans = homeMessageBeans.getDatas();
                if (datasBeans != null && datasBeans.size() > 0) {
                    mList.clear();
                    mList.addAll(datasBeans);
                } else {
                    postShowNoDataViewEvent(true);
                }
            }
        });
    }

    @Override
    public void loadMore() {
        pageNo++;

        mModel.getMessageList(pageNo).subscribe(new RefreshObserver<HomeMessageBean, WorkViewModel>(this) {
            @Override
            public void onSuccess(HomeMessageBean homeMessageBeans) {
                List<HomeMessageBean.DatasBean> datasBeans = homeMessageBeans.getDatas();
                if (datasBeans != null && datasBeans.size() > 0) {
                    mList.addAll(datasBeans);
                }
            }
        });
    }
}
